package com.sise.netty.server端和client端通信案例.demo2;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringEncoder;

/**
 * @author idea
 * @data 2019/4/6
 */
public class Client {

    public static void main(String[] args) throws InterruptedException {
        Bootstrap bs=new Bootstrap();
        NioEventLoopGroup group=new NioEventLoopGroup();
        bs.group(group)
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<Channel>() {
            @Override
            protected void initChannel(Channel channel) throws Exception {
                channel.pipeline().addLast(new StringEncoder());
            }
        });

        Channel channel=bs.connect("localhost",8000).channel();
        while(true){
            System.out.println("发送数据");
            channel.writeAndFlush(new String("this is test"));
            Thread.sleep(1000);

        }


    }
}
